package parser;

import args.Args;

import java.util.HashMap;

/**
 * @author leo
 * @date 2021/6/21
 */
public class ArgsParser {
    private static final String LOGGING_FLAG = "-l";
    private static final String PORT_FLAG = "-p";
    private static final String DIRECTORY_FLAG = "-d";
    private final String args;
    private final HashMap<String,Args> map = new HashMap<>();

    public ArgsParser(String args) {
        this.args = args;
    }

    public void classifyAndParse(String args) {
        map.put(LOGGING_FLAG,new LoggingParser().parse(args));
        map.put(PORT_FLAG,new PortParser().parse(args));
        map.put(DIRECTORY_FLAG,new DirectoryParser().parse(args));
    }

    public Object getFlag(String arg) {
        classifyAndParse(args);
        return map.get("-"+arg).getValue();
    }
}
